<template>
	<view class="index-box">
		<!-- 轮播图 -->
		<mxg-banner :bannerList="bannerList"></mxg-banner>
		<!-- 分类11区域11 d -->
		<category-box :jbstate="jbstate" :categoryList="categoryList"></category-box>
		<view class="list-container">
			<swiper-course name="免费专业咨询" :courseData="freeDoctorList" :params="{type: 1}"></swiper-course>
			<scroll-course name="专家咨询" :courseData="doctorList" :params="{type: 2}"></scroll-course>
			<list-course name="推荐文章" :courseData="articleList" :params="{type: 3}"></list-course>
		</view>
	</view>
</template>

<script>
	import searchInput from '@/components/common/search-input.vue'
	import mxgBanner from '@/components/common/mxg-banner.vue'
	import categoryBox from './components/category-box.vue'

	import swiperCourse from './components/swiper-course.vue'
	import scrollCourse from './components/scroll-course.vue'
	import listCourse from './components/list-course.vue'

	import api from '@/api/course.js'

	import dapi from '@/api/doctor.js'
	import articleApi from '@/api/article.js'


	export default {

		components: {
			searchInput,
			mxgBanner,
			categoryBox,
			swiperCourse,
			scrollCourse,
			listCourse
		},
		async onLoad(option) {
			// this.superior = option.superior
			uni.setStorageSync('superior', option.superior);
			// // 查询数据
			this.loadBannerData()

			this.loadDoctorData()
			this.loadArticleData()
			this.jstate()

		},
		data() {
			return {
				superior:'',
				bannerList: [],
				hotCourseList: [], //热门列表数据111
				payCourseList: [],
				newCourseList: [],
				categoryList: [],
				freeDoctorList: [], //免费专业咨询
				doctorList: [], //专家咨询
				articleList: [], //推荐文章
				jbstate:1//1显示 上线用的


			}
		},
		methods: {
			onShareAppMessage: function(e) {
				let title = '孕道'
				return {
					title: title,
					path: 'pages/index/index'
				}
			},


			// 首页 专家列表
			async loadDoctorData() {
				const {
					data
				} = await dapi.getHomeList()
				this.freeDoctorList = data[0]
				this.doctorList = data[1]

			},
			
			// 上线用  1显示
			async jstate() {
				const {
					code
				} = await articleApi.jbstate()
				this.jbstate = code
			
			},
			
			
		


			// 首页 推荐文章1
			async loadArticleData() {
				const {
					data
				} = await articleApi.getArticleHome()
				this.articleList = data

			},
			// 查询轮播图数据11
			async loadBannerData() {
				const {
					data
				} = await dapi.getAdvertList()
				this.bannerList = data
				// console.log('data', data)
			},

			// 查询分类数据
			async loadCateData() {
				const {
					data
				} = await api.getCategoryList()
				this.categoryList = data
				// console.log('cate', this.categoryList)
			},

			// 查询热门推荐数据
			async loadHotCourseData() {
				const {
					data
				} = await api.getList({
					sort: 'hot'
				}, 1, 8)
				this.hotCourseList = data.records
				// console.log('hotCourseList', this.hotCourseList)
			},
		}
	}
</script>

<style>
	.list-container {
		padding: 0 30rpx;
	}
</style>
